import React, { Component } from 'react';
import SelectedImage from '@/components/plugins/selectImage/SelectImage';
import { connect } from 'dva';

export default class ImageForm extends Component {
    componentDidMount() {
        this.showModal();
    }
    render() {
        return (
            <SelectedImage onRef={this.imgModal} cdnUrl={window.cdnUrl} selectImage={this.onImageChange} />
        );
    }
    imgModal = ref => {
        this.imgmodal = ref;
    };
    showModal = () => {
        this.imgmodal.handleShowModal();
    };
    OpenImageModal = () => {
        this.imgmodal.handleShowModal();
    };
    onImageChange = res => {
        const { callback } = this.props;
        let imgInfo = { imageUrl: res.imageUrl, width: res.width, height: res.height };

        imgInfo.html = `<p class="${'xkd-richtext-img-small'}"><img src="${res.imageUrl}"  style=width:"${res.width};hight:${res.height}" /></p>`
        callback(imgInfo)
        this.imgmodal.handleModalVisible();
    };
}
